const db = require('./db');

const academySchema = new db.Schema({
  name:{type:String,default:'默认学院'},
})

const academyModel = db.model('academySchema',academySchema,'academy');

const adminSchema = new db.Schema({
  name:String,
  role:String,
  // permissions:[String],
  email:String,
  phone:Number,
  truename:String,
  academy:{type:db.Schema.Types.ObjectId,ref:'academySchema'},
  password: String
});

const adminModel = db.model('adminSchema',adminSchema,'admin');

const stageSchema = new db.Schema({
  name:{type:String,default:'默认阶段'},
  academy:{type:db.Schema.Types.ObjectId,ref:'academySchema'},//归属哪个学院
})

const stageModel = db.model('stageSchema',stageSchema,'stage');


// 试题表
const questionSchema = new db.Schema({
  title:{type:String,default:'默认题干'},
  cate:{
    type:Number,//1单选，2多选，3判断，4简答
    default:1
  },
  belong:{
    type:{type:db.Schema.Types.ObjectId,ref:'stageSchema'},//归属哪个学院哪个阶段
  },
  difficulty:{
    type:Number,//难度，1简单，2中等，3困难
    default:1
  },
  options:[
    {
      title:{type:String,default:'默认选项'},
      isRight:{type:Boolean,default:false},//是否为正确答案
    },
  ],
  answer:{
    type:String,
    default:'默认解析'
  }
})

const questionModel = db.model('questions',questionSchema,'questions')

//试卷表
const paperSchema = new db.Schema({
  name:{type:String,default:'默认试卷名称'},
  time:[Number],
  pass_score:{type:Number,default:60},
  out:{type:Number,default:100},
  creator:{type:db.Schema.Types.ObjectId,ref:'adminSchema'},
  questions:[{type:db.Schema.Types.ObjectId,ref:'questionSchema'}],
  type:{type:Boolean,default:false},//随机抽取0/固定题目1
})
const paperModel = db.model('paper',paperSchema,'paper')

//路由表
const routeSchema = new db.Schema({
  url: String,
  pid: {
    type: db.Types.ObjectId,
    ref: 'route'
  }
})

const routeModel = db.model('route', routeSchema, 'route')

const studentSchema = new db.Schema({
  name: String,
  tid: String,
  card: String,
  sex: Boolean,
  clazz: String,
  phone: Number,
  address: String,
  ice: String
})

const studentModel = db.model('student', studentSchema, 'student')

module.exports = {
  academyModel,
  stageModel,
  questionModel,
  paperModel,
  adminModel,
  routeModel,
  studentModel
};